<link rel="stylesheet" type="text/css" href="../css/pintuer.css">
<link rel="stylesheet" type="text/css" href="../css/admin.css">
<link rel="stylesheet" type="text/css" href="../css/manage.css">
<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');
ini_set("display_errors",1);
if ($_POST['but']=="add"){
	if(checkstr(trim($_POST['productname']))=="") show_automsg('请输入产品名称',YMCURL.'productsadd');
	$categoryid=checkstr(trim($_POST['categoryid']));
	$price=checkstr($_POST['price']);
	// $scprice=checkstr($_POST['scprice']);
	$proimg=RemoveXSS($_POST['proimg']);
	$num=checkstr($_POST['num']);
	$style_1=checkstr(trim($_POST['style_1']));
	$style_2=checkstr(trim($_POST['style_2']));
	$style_3=checkstr(trim($_POST['style_3']));

	$style_1_value=checkstr(trim($_POST['style_1_value']));
	$style_2_value=checkstr(trim($_POST['style_2_value']));
	$style_3_value=checkstr(trim($_POST['style_3_value']));
	$memo=addslashes($_POST['memo']);
	if(!$categoryid){
		show_automsg('请选择产品分类',YMCURL.'productsadd');
	}
    if($price==""){
    	show_automsg('请输入单价',YMCURL.'productsadd');

    }
    if(trim($num)==""){
    	show_automsg('请输入数量',YMCURL.'productsadd');

    }
    $arr['productname']=trim($_POST['productname']);
    $arr['categoryid']=$categoryid;
    $arr['price']=$price;
    // $arr['scprice']=$scprice;
    $arr['proimg']=$proimg;
    $arr['num']=$num;
    $arr['memo']=$memo;
    $arr['addtime']=time();
    if($style_1&&$style_1_value){
        $arr['style_1']=$style_1;
        $arr['style_1_value']=$style_1_value;
    }
    if($style_2&&$style_2_value){
    	$arr['style_2']=$style_2;
    	$arr['style_2_value']=$style_2_value;
    }
    if($style_3&&$style_3_value){
    	$arr['style_3']=$style_3;
    	$arr['style_3_value']=$style_3_value;
    }

    $sql=getinsertsql($arr,'ld_product');
	$db->query($sql,5);
	$pid=$db->fval;
    if($num>0){
        $xrr['productid']=$pid;
        $xrr['productname']=trim($_POST['productname']);
        $xrr['num']=$num;
        $xrr['addtime']=time();
        $xrr['adminname']=$_SESSION['houname'];
        $xrr['adminid']=$_SESSION['houid'];
        $sql=getinsertsql($xrr,'ld_rks');
        $db->query($sql,5);
    }
    show_automsg('添加产品成功',YMCURL.'products');

}

if ($_POST['but']=="edit1"){
	$id=$_POST['pid'];
	$hint="";
	$productname=checkstr(trim($_POST['productname']));
	if(trim($productname)=="") show_automsg('请输入产品名称',YMCURL.'productsadd&action=edit&id='.$id);
	$categoryid=checkstr(trim($_POST['categoryid']));
    $proimg=RemoveXSS($_POST['proimg']);
    $price=checkstr($_POST['price']);
    // $scprice=checkstr($_POST['scprice']);
	$memo=addslashes($_POST['memo']);
    if($price==""){
    	show_automsg('请输入单价',YMCURL.'productsadd&action=edit&id='.$id);

    }
    if(!$categoryid){
		show_automsg('请选择产品分类',YMCURL.'productsadd');
	}
    $pname=trim($productname);
    $style_1=checkstr(trim($_POST['style_1']));
	$style_2=checkstr(trim($_POST['style_2']));
	$style_3=checkstr(trim($_POST['style_3']));

	$style_1_value=checkstr(trim($_POST['style_1_value']));
	$style_2_value=checkstr(trim($_POST['style_2_value']));
	$style_3_value=checkstr(trim($_POST['style_3_value']));
    $sql="update ld_product set productname='".$pname."',categoryid=".$categoryid.",proimg='".$proimg."',price='".$price."',memo='".$memo."'";
    if ($proimgstr!=""){
    	$sql.=",proimg='".$proimgstr."'";
    }	
    if($style_1&&$style_1_value){
    	$sql.=",style_1='".$style_1."'";
    	$sql.=",style_1_value='".$style_1_value."'";
    }
    if($style_2&&$style_2_value){
    	$sql.=",style_2='".$style_2."'";
    	$sql.=",style_2_value='".$style_2_value."'";
    }
    if($style_3&&$style_3_value){
    	$sql.=",style_3='".$style_3."'";
    	$sql.=",style_3_value='".$style_3_value."'";
    }
    $sql.=" where id=".$id;
    $db->query($sql,4);
     show_automsg('修改产品成功',YMCURL.'productsadd&action=edit&id='.$id);

}

$action=$_GET['action'];

if ($action=="edit"){
	$id=$_GET['id'];
	$db->query("select * from ld_product where id='".$id."'",2);
	$rs1=$db->rs;
}

$actionstr=($action=="edit")?"修改":"添加";
$action_1=($action=="edit")?"edit1":"add";

?>

<script>
function frmchk(frm){
	if (frm.productname.value=="")
	{
		alert("请输入产品名称");
		frm.productname.focus();
		return false;
	}
}
</script>
<div class="righttop">
  <span class="icon-home"></span> 首页 <span class="gray">/</span> 产品管理
</div>
<div class="panelbox">
    <div class="panel admin-panel">
        <div class="panel-head">
          <strong><span class="icon-shopping-cart"></span>
            产品<?php echo $actionstr?>
          </strong>
        </div>
        <div class="body-content">
        	<!-- 表格表格 -->
        	<form action="?lsaction=<?php echo $lsaction?>" method="post" enctype="multipart/form-data" name="form1" onSubmit="return frmchk(this);">
			  <table class="modifytable">
				<tr>
				<input name="pid" type="hidden" value="<?php echo $rs1['id'];?>">
				  <td class="leftb"><p>产品名称:</p>	    </td>
				  <td>
				  <input name="productname" type="text" id="productname" value="<?php echo $rs1["productname"]?>" class="input w50">
				  </td>
				</tr>
				<tr>
				  <td class="leftb"><p>品牌分类:</p>	    </td>
				  <td>
				  <select name="categoryid" id="categoryid">
				       <?php 
				       $cate=array("请选择","商品积分消费产品","商城消费产品");
				       foreach($cate as $key=>$val){ ?>
								<option value="<?php echo $key; ?>" <?php echo $rs1['categoryid']==$key ? "selected='selected'" : "" ?>><?php echo $val;?></option>
							<?php } ?>
				  </select>
				  </td>
				</tr>
				<tr>
				  <td class="leftb">图片路径:</td>
				  <td>
				  	<input name="proimg" type="text" id="proimg" value="<?php echo $rs1['proimg'];?>" class="input w50"> 
				  	<?php
				  	if($rs1['proimg']){
				  		echo "<a href=".$rs1['proimg']." target='_blank'><img src=".$rs1['proimg']." width=80/></a>";
				  	}

				  	?>
				  	</td>
			   </tr>
				<tr>
				  <td class="leftb">价格:</td>
				  <td><input name="price" type="text" id="price" value="<?php echo $rs1["price"]?>" class="input w50"></td>
				</tr>
				<tr style="display:none">
				  <td class="leftb">消费价格:</td>
				  <td><input name="scprice" type="text" id="price" value="<?php echo $rs1["scprice"]?>" class="input w50">元</td>
				</tr>

			    <?php if($action!="edit"){?>
			    <tr>
				  <td class="leftb">库存数量:</td>
				  <td><input name="num" type="text" id="num" value="<?php echo $rs1["num"]?>" class="input w50"></td>
				  </tr>
			    <?php }?>
			     <tr>
				  <td class="leftb">属性一:</td>
				  <td><input name="style_1" type="text" id="style_1" value="<?php echo $rs1["style_1"]?>" class="input w50">
				  <input name="style_1_value" type="text" id="style_1_value" value="<?php echo $rs1["style_1_value"]?>" class="input w50"></td>
				  </tr>
				<tr>
				  <td class="leftb">属性二:</td>
				  <td><input name="style_2" type="text" id="style_2" value="<?php echo $rs1["style_2"]?>" class="input w50">
				  <input name="style_2_value" type="text" id="style_2_value" value="<?php echo $rs1["style_2_value"]?>" class="input w50"></td>
				</tr>
				<tr>
				  <td class="leftb">属性三:</td>
				  <td><input name="style_3" type="text" id="style_3" value="<?php echo $rs1["style_3"]?>" class="input w50">
				  <input name="style_3_value" type="text" id="style_3_value" value="<?php echo $rs1["style_3_value"]?>" class="input w50"></td>
				</tr>
				<tr>
				  <td class="leftb">说明:</td>
				  <td><textarea name="memo"  id="memo"><?php echo htmlspecialchars($rs1["memo"]);?></textarea></td>
				  </tr>

				  <tr>
				  <td class="leftb"></td>
				  <td>
				    <input type="hidden" name="id" value="<?php echo $id?>">
			        <input type="hidden" name="pageno" value="<?php echo $pageno?>">
			       
			        <!-- <span class="icon-plus"></span> <?php echo $actionstr?></button>	   -->
			        <?php
			        if($actionstr=='添加'){
			        	echo ' <button class="button bg-main" type="submit"  value="add" id="but"  name="but"><span class="icon-plus"></span> '. $actionstr.'</button>';

			        }else{
			        	echo ' <button class="button bg-main" type="submit"  id="but" value="edit1" name="but"><span class="icon-plus"></span>'. $actionstr.'</button>';

			        }
			        ?>
			        </td>
				  </tr>
			    </table>
			</form>
        	<!-- 结束结束 -->
        </div>

    </div>
</div>
<script type="text/javascript">
var ue = UE.getEditor('memo',{
	initialFrameWidth:1000,
	initialFrameHeight:400
});
</script>
